package todo.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;

public class DeleteClickHandler implements ClickHandler {

	TodoGWeb app = null;
	
	public DeleteClickHandler(TodoGWeb app) {
		this.app = app;
	}

	@Override
	public void onClick(ClickEvent event) {
		System.out.println(event.toString());
		Label lbl = (Label) event.getSource();
		Long id = new Long(lbl.getTitle());
		
		app.todoService.delete(id, new AsyncCallback<Void>() {
			
			@Override
			public void onSuccess(Void result) {
				// TODO Auto-generated method stub
				app.renderTodoTable();
			}
			
			@Override
			public void onFailure(Throwable caught) {
				// TODO Auto-generated method stub
				
			}
		});
		
	}

}
